﻿using System;
using System.Collections.Generic;
using System.Drawing;
using RaytracerLib.Layers;
using RaytracerLib.MathLib;
using TomanuExtensions;
using RaytracerLib.Layers.OverlayCorrectors;
using System.Linq;
using RaytracerLib.Postprocessing;
using YAXLib;

namespace RaytracerLib.Resamplers
{
    public abstract class Resampler
    {
        internal Film Film;

        public static Resampler Create(ResamplerType a_type)
        {
            if (a_type == ResamplerType.Exact)
                return new ExactResampler();
            else if (a_type == ResamplerType.LocalGrid)
                return new LocalGridResampler();
            else if (a_type == ResamplerType.Resizer)
                return new ResizerResampler();
            else if (a_type == ResamplerType.NetResizer)
                return new NetResizerResampler();
            else
                throw new NotImplementedException();
        }

        internal Rectangle GetAffectedRect(Rectangle a_dest_rect)
        {
            int border = FilterRay.Ceiling();
            a_dest_rect.Inflate(border, border);
            a_dest_rect.Intersect(new Rectangle(0, 0, Film.Width, Film.Height));
            return a_dest_rect;
        }

        internal virtual void RenderEnd()
        {
        }

        internal abstract double FilterRay { get; }
        internal abstract void Resample(Rectangle a_rect, ColorArrayFloat a_dest);
        internal abstract void RenderStart(RenderStartPhase a_phase);
        internal abstract void SetRayColor(Vector2 a_pixel, ColorFloat a_color);
        public abstract ResamplerType ResamplerType { get; }
    }
}